Ext.define('HGMIDE.view.IDESettingPanel', {
	extend: 'Ext.Panel',
	xtype: 'ideSettingPanel',
	requires: ['HGMIDE.view.AlterPwd'],
	config: {
		id: 'ide_setting_panel',
		modal: true,
		hideOnMaskTap: true,
		centered: true,
		width: '600px',
		height: '500px',
		items: [{
			id: 'setting_title',
			xtype: 'titlebar',
			title: I18N.setting0,
			height: '25px',
			cls: 'settingTitle',
			items: [{
				xtype: 'img',
				src: 'resources/images/t_gb.png',
				align: 'right',
				docked: 'top',
				width: '35px',
				height: '35px',
				cls: 'gbBtn',
				listeners: {
					tap: function () {
						Ext.getCmp('ide_setting_panel').hide();
					}
				}
			}]
		}, {
			xtype: 'container',
			layout: {
				type: 'vbox'
			},
			items: [{
				xtype: 'container',
				layout: {
					type: 'hbox'
				},
				items: [{
					xtype: 'label',
					html: I18N.preview_size,
					cls: 'settingLable'
				}, {
					id: 'widthController',
					xtype: 'numberfield',
					value: 320,
					width: '140px',
					height: '40px',
					maxValue: 10000,
					minValue: 1,
					listeners: {
						change: function (textfield, newValue,
							oldValue, eOpts) {
							var currentEmulatorScreen = EmulatorManager.currentEmulator;
							if (currentEmulatorScreen != null) {
								var height = Ext
									.getCmp('heightController')
									.getValue();
								var width = Ext
									.getCmp('widthController')
									.getValue();
								var id = EmulatorManager.currentEmulator
								.getId();
								var emulatorObj = EmulatorManager
								.getEmulatorObj(id);
								if (height == null ||
									width == null) {
									Ext
										.getCmp('heightController')
										.setValue(emulatorObj.height);
									Ext
										.getCmp('widthController')
										.setValue(emulatorObj.width);
								} else {
									if(width <= 0){
										width = 1;
										Ext.getCmp('widthController').setValue(width);
									}
									if(height <= 0){
										height = 1;
										Ext.getCmp('heightController').setValue(height);
									}
									emulatorObj.height = height;
									emulatorObj.width = width;
									emulatorObj.isFullScreen = false;
									emulatorObj.isRotated = false;
									Emulator.predefineWidth = width;
									Emulator.predefineHeight = height;
									Emulator
										.regulateScreenSizeWithNoZoom(
											EmulatorManager
											.getEmulatorObj('emulator' +
												id
												.substring(id
													.indexOf('r') +
													1)),
											newValue,
											height);
									var fullscreenBtn = Ext
										.getCmp('fullScreenBtn' +
											id
											.substring(id
												.indexOf('r') +
												1));
									var pluginSideBtn = Ext
										.getCmp('pluginSideBtn' +
											id
											.substring(id
												.indexOf('r') +
												1));
									fullscreenBtn
										.setCls('qpBtn');
									var list = Ext
										.getCmp('ide_plugin_manage_space');
									if (list.getHidden()) {
										pluginSideBtn
											.setCls('pluginSideBtn1');
									} else {
										pluginSideBtn
											.setCls('pluginSideBtn');
									}
								}
							}
						}
					}
				}, {
					xtype: 'img',
					width: '12px',
					height: '12px',
					cls: 'sizeImg',
					src: 'resources/images/t_xy.png'
				}, {
					id: 'heightController',
					xtype: 'numberfield',
					minWidth: 0,
					value: 568,
					width: '140px',
					height: '40px',
					maxValue: 10000,
					minValue: 1,
					listeners: {
						change: function (textfield, newValue,
							oldValue, eOpts) {
							var currentEmulatorScreen = EmulatorManager.currentEmulator;
							if (currentEmulatorScreen != null) {
								var height = Ext
									.getCmp('heightController')
									.getValue();
								var width = Ext
									.getCmp('widthController')
									.getValue();
								var id = EmulatorManager.currentEmulator
									.getId();
								var emulatorObj = EmulatorManager
									.getEmulatorObj(id);
								if (height == null ||
									width == null) {
									Ext
										.getCmp('heightController')
										.setValue(emulatorObj.height);
									Ext
										.getCmp('widthController')
										.setValue(emulatorObj.width);
								} else {
									if(width <= 0){
										width = 1;
										Ext.getCmp('widthController').setValue(width);
									}
									if(height <= 0){
										height = 1;
										Ext.getCmp('heightController').setValue(height);
									}
									emulatorObj.height = height;
									emulatorObj.width = width;
									emulatorObj.isFullScreen = false;
									Emulator.predefineWidth = width;
									Emulator.predefineHeight = height;
									Emulator
										.regulateScreenSizeWithNoZoom(
											EmulatorManager
											.getEmulatorObj('emulator' +
												id
												.substring(id
													.indexOf('r') +
													1)),
											width,
											newValue);
									var fullscreenBtn = Ext
										.getCmp('fullScreenBtn' +
											id
											.substring(id
												.indexOf('r') +
												1));
									var pluginSideBtn = Ext
										.getCmp('pluginSideBtn' +
											id
											.substring(id
												.indexOf('r') +
												1));
									fullscreenBtn
										.setCls('qpBtn');
									var list = Ext
										.getCmp('ide_plugin_manage_space');
									if (list.getHidden()) {
										pluginSideBtn
											.setCls('pluginSideBtn1');
									} else {
										pluginSideBtn
											.setCls('pluginSideBtn');
									}
								}
							};
						}
					}
				}, {
					xtype: 'img',
					width: '111px',
					height: '35px',
					cls: 'sizeListImg',
					src: 'resources/images/t_lb.png',
					listeners: {
						tap: function () {
							// show size list panel
							if (Util.sizelistvisiable) {
								Util.sizeListPanel.hide();
							} else {
								Util.sizeListPanel.showBy(this);
							}
						}
					}
				}]
			}, {
				xtype: 'container',
				layout: {
					type: 'hbox'
				},
				items: [{
					xtype: 'label',
					html: I18N.user_info,
					cls: 'settingLable'
				}, {
					xtype: 'ideUserList',
					width: '400px',
					height: '120px'
				}, {
					xtype: 'img',
					width: '35px',
					height: '35px',
					src: 'resources/images/t_tj.png',
					cls: 'settingAddImg',
					listeners: {
						tap: function () {
							Util.editUser(0);
						}
					}
				}]
			}, {
				xtype: 'container',
				layout: {
					type: 'hbox'
				},
				items: [{
					xtype: 'label',
					html: I18N.service,
					cls: 'settingLable'
				}, {
					xtype: 'ideServiceList',
					width: '400px',
					height: '120px'
				}, {
					xtype: 'img',
					width: '35px',
					height: '35px',
					cls: 'settingAddImg',
					src: 'resources/images/t_tj.png',
					listeners: {
						tap: function () {
							Util.editService(0);
						}
					}
				}]
			}, {
				xtype: 'container',
				layout: {
					type: 'hbox'
				},
				items: [{
					xtype: 'label',
					html: I18N.developer,
					cls: 'settingLable'
				}, {
					id: 'currentDevInfo',
					xtype: 'label',
					style: 'color:red;',
					html: '<div class="devInfo"><p>NBHG DEV</p><p>lin@163.com</p><p>NB-DEV.HGMCA</p><div>'
				}]
			}]
		}, {
			xtype: 'label',
			html: '<a style="color:#157dfb" href="#" onclick="javascript:Util.showAlterPwdPanel();">' +
				I18N.alterPwd + '</a>',
			cls: 'alterPwd'
		},{
			id: 'ide_setting_version',
			xtype: 'container',
			items: [{
				xtype: 'label',
				html: I18N.title+'&nbsp;'+I18N.ide_version
			}]
		}, {
			xtype: 'spacer'
		}],
		listeners: {
			show: function () {
				Util.isSettingPanelShowing = true;
				if (EmulatorManager.currentEmulator == null) {
					Ext.getCmp('widthController')
						.setValue(Emulator.predefineWidth);
					Ext.getCmp('heightController')
						.setValue(Emulator.predefineHeight);
				} else {
					var id = EmulatorManager.currentEmulator.id;
					var emulatorObj = EmulatorManager.getEmulatorObj(id);
					Ext.getCmp('widthController').setValue(emulatorObj.width);
					Ext.getCmp('heightController').setValue(emulatorObj.height);
				}
			}
		}
	}
});